package com.raulraja.model.domain;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

/**
 * An object that encapsualtes pagination over list of records
 */
@XmlRootElement(namespace = PersistentEntity.NAMESPACE)
@XmlType(name = "paginatedList", namespace = PersistentEntity.NAMESPACE)
public class PaginatedList<Entity> {

	/**
	 * the total amount of items available in the data store
	 */
	private long count;

	/**
	 * the starting record displayed on the list
	 */
	private long start;

	/**
	 * the size of this list
	 */
	private long size;

	/**
	 * the records contained on the list
	 */
	private List<Entity> items = new ArrayList<Entity>();

	/**
	 * default constructor
	 */
	public PaginatedList() {
		super();
	}

	/**
	 * Constructor that takes the data
	 * @param count the total amount of items available in the data store
	 * @param start the starting record displayed on the list
	 * @param items the records contained on the list
	 */
	public PaginatedList(long count, long start, List<Entity> items) {
		this();
		setCount(count);
		setStart(start);
		setItems(items);
		setSize(items.size());
	}

	/**
	 * @return the total amount of items available in the data store
	 */
	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	/**
	 * @return the starting record displayed on the list
	 */
	public long getStart() {
		return start;
	}

	public void setStart(long start) {
		this.start = start;
	}

	/**
	 * @return the size of this list
	 */
	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	/**
	 * @return the records contained on the list
	 */
	@XmlElementWrapper(name = "items")
	@XmlElements({
            @XmlElement(name="person", type=Person.class, namespace = PersistentEntity.NAMESPACE),
			@XmlElement(name="property", type=Object.class, namespace = PersistentEntity.NAMESPACE)
    })
	public List<Entity> getItems() {
		return items;
	}

	public void setItems(List<Entity> items) {
		this.items = items;
	}
}
